export function formatDate(date, fmt) {
  date = new Date(date)
  if (/(Y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  let ruleAll = {
    'M+': date.getMonth() + 1,
    'D+': date.getDate(),
    'h+': date.getHours(),
    'm+': date.getMinutes(),
    's+': date.getSeconds()
  }
  for (let key in ruleAll) {
    let str = ruleAll[key] + ''
    let result = new RegExp(`(${key})`).test(fmt)
    if (result) {
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 2) ? str : padLeftZero(str))
    }
  }
  return fmt
}

function padLeftZero(str) {
  return ('00' + str).substr(str.length)
}




